# -*- coding: utf-8 -*-

import hashlib
import settings

def file_hash(ip, path, name, permission, last_modified):
    return hashlib.md5(ip + path + "/" + name + permission + last_modified).hexdigest()

def logfile(ip):
    return open("%s%s.logfile" % (settings.DATA_DIRECTORY, ip), "ab")
    
# Thanks http://blogmag.net/blog/read/38/Print_human_readable_file_size
def size_h(num):
    if num is None:
        return None
    for x in ["b","KB","MB","GB","TB"]:
        if num < 1024.0:
            return "%3.1f%s" % (num, x)
        num /= 1024.0
